/**
 * @file      config_api.h
 * @brief
 * @version   1.0
 * @date      2023.12.14
 *
 * @copyright Copyright (c) 2018 UCchip Technology Co.,Ltd. All rights reserved.
 *
 * Change Logs:
 * Date          Author       Notes
 * 2023.12.14    ucchip       the first version
 *
 */

#ifndef __CONFIG_API_H__
#define __CONFIG_API_H__

#include "config_data.h"

#define CFG_DATA_HEAD "UC"
#define CFG_COMPANY "ucchip"
#define CFG_DEV_ID (0xFFFFFFFF)
#define CFG_IP_ADDR "192.168.1.200"
#define CFG_MASK_ADDR "255.255.255.0"
#define CFG_GATEWAY_ADDR "192.168.1.1"
#define CFG_PRIMARY_DNS "114.114.114.114"
#define CFG_SECONDARY_DNS "114.114.115.115"
#define CFG_PPP_APN "CMIOT"
#define CFG_SOFTWARE_VERSION "v1.8.1"
#define CFG_ASSIGN_START_ADDR (1)
#define CFG_ASSIGN_END_ADDR (1664)
#define CFG_ADDR_NUM (128)
#define CFG_AUTH_KEY "123456"
#define CFG_MQTT_SERVER_URL "117.172.29.2"
#define CFG_MQTT_SERVER_PORT (36106)
#define CFG_MQTT_CLIENT_ID "client4294967295"
#define CFG_FTP_PORT (21)

#define CFG_TX_POWER (21)
#define CFG_SPECTRUM_IDX (3)
// 工厂默认使用频点5和15.镜像开机默认5、15为了工厂烧录后测试方便，实际使用时请根据需求修改
#define CFG_DEFA_FREQ1 (5)
#define CFG_DEFA_FREQ2 (15)
#define CFG_SUBSYSTEM_ID (0x21456981)
#define CFG_PGAING_TX_AWAKEN_ID (30)
#define CFG_PGAING_TX_SEND_TIME (1000)
#define CFG_SYNC_PGAING_DEV_ID (0x1020304)
#define CFG_SYNC_PGAING_PERIOD (10)
#define CFG_SYNC_PGAING_SEND_ROUND (1)
#define CFG_SYNC_PGAING_COUNTINUE_FN (1)
#define CFG_FN_BROADCAST_CYCLE (11)
#define CFG_TRANSPORT_PERIOD (1000)
#define CFG_TRANSPORT_FRAME_NUM (2)
#define CFG_BC_SEND_ROUND (3)
#define CFG_UC_RESEND_TIMES (1)
#define CFG_TS_PERIOD (5)

#define CFG_DL_SUBF_BLOCK_SIZE (12)
#define CFG_DL_SUBF_SEND_ROUND (1)

#define NETDEV_INTERFACE "e0"
#define NETDEV_WIFI "w0"
#define NETDEV_CAT1 "pp"

#define DEFAULT_NETDEV_INTERFACE "e0 (Default)"
#define DEFAULT_NETDEV_WIFI "w0 (Default)"
#define DEFAULT_NETDEV_CAT1 "pp (Default)"
#define MQTT_TIMEOUT (5 * 60)

#define GATEWAY_RESET_ALARM_OFF (24)

#define CFG_HARDWARE_VERSION_UNKNOWN "unknown"
#define CFG_HARDWARE_VERSION_V1_3 "v1.3"
#define CFG_HARDWARE_VERSION_V1_5 "v1.5"
#define CFG_HARDWARE_VERSION_V1_6 "v1.6"
typedef enum
{
    UC_GW_HW_VERSION_V1_3 = 0x0F,
    UC_GW_HW_VERSION_V1_5 = 0x00,
    UC_GW_HW_VERSION_V1_6 = 0x01,
} uc_ststic_hw_version_e;

typedef enum
{
    UC_STATIC_MAJOR_VERSION = 2,
} uc_static_major_version_e;

typedef enum
{
    UC_STATIC_MINOR_VERSION = 5,
} uc_static_minor_version_e;

typedef enum
{
    UC_STATIC_VERSION_V1 = 1, // default value
    UC_STATIC_VERSION_V2_5 = ((UC_STATIC_MAJOR_VERSION << 8) | UC_STATIC_MINOR_VERSION),
} uc_static_version_e;

typedef enum
{
    UC_SWITCH_OFF = 0,
    UC_SWITCH_ON = 1,
} uc_switch_e;

typedef enum
{
    UC_NORMAL_MODE = 0,
    UC_FACTORY_MODE = 1,
    UC_TRANSMISSION_MODE = 2,
    UC_TRANSMISSION_TIME_SLOT_MODE = 3,
    UC_RF_TEST_MODE = 4,      // 网关射频测试，仅测试人员使用
    UC_AP_RF_TEST_MODE = 5,   // 网关AP射频测试，仅测试人员使用
    UC_SYNC_RF_TEST_MODE = 6, // 网关同步助手射频测试，仅测试人员使用
} uc_work_mode_e;

typedef enum
{
    UC_UP_ENCODE_NONE = 0,
    UC_UP_ENCODE_BASE64 = 1,
    UC_UP_ENCODE_HEX = 2,
} uc_up_encode_e;

typedef enum
{
    UC_UP_DATA_FLOW_TO_NET = 0,
    UC_UP_DATA_FLOW_TO_UART = 1,
    UC_UP_DATA_FLOW_TO_BT = 2,
} uc_up_data_flow_e;

typedef enum
{
    NETDEV_AUTO,
    NETDEV_MANUAL,
} uc_netdev_policy_e;

typedef enum
{
    ETH_DEV = 0,
    WIFI_DEV,
    CAT1_DEV,
    DEV_TYPE_MAX
} uc_netdev_type_e;

typedef enum
{
    UC_TS_NONE = 0,
    UC_TS_GPS = 1,
    UC_TS_1588 = 2,
    UC_TS_SYNC_ASSISTANT = 3,
} uc_ts_mode_e;

typedef enum
{
    UC_1588_DEV_SLAVE = 0,
    UC_1588_DEV_MASTER = 1,
} uc_1588_dev_e;

typedef enum
{
    UC_KEY_TYPE1 = 1,
} uc_key_type_e;

typedef enum
{
    UC_SYMBOL_LEN_128 = 0,
    UC_SYMBOL_LEN_256 = 1,
    UC_SYMBOL_LEN_512 = 2,
    UC_SYMBOL_LEN_1024 = 3,
} uc_symbol_len_e;

typedef enum
{
    UC_DLUL_RATIO_1_1 = 0,
    UC_DLUL_RATIO_1_2 = 1,
} uc_dlul_ratio_e;

typedef enum
{
    UC_GROUP_NUM_1 = 0,
    UC_GROUP_NUM_2 = 1,
    UC_GROUP_NUM_4 = 2,
    UC_GROUP_NUM_8 = 3,
} uc_group_num_e;

typedef enum
{
    UC_BT_VALUE_12 = 0,
    UC_BT_VALUE_03 = 1,
} uc_bt_value_e;

typedef enum
{
    UC_MCS_0 = 0,
    UC_MCS_1 = 1,
    UC_MCS_2 = 2,
    UC_MCS_3 = 3,
    UC_MCS_4 = 4,
    UC_MCS_5 = 5,
    UC_MCS_6 = 6,
    UC_MCS_7 = 7,
    UC_MCS_AUTO = 8,
} uc_mcs_e;

/**
 * @brief 从flash读取静态数据，然后复制有效字段到g_backup_data。
 *
 */
void uc_static_data_init(void);

/**
 * @brief 将静态数据恢复出厂设置
 *
 */
void uc_static_data_reset(void);

/**
 * @brief 获取版本静态数据版本
 *
 * @return 版本信息
 */
short uc_static_get_version(void);

/**
 * @brief 将g_backup_data写入到flash
 *
 */
void uc_static_save_op(void);

//{ wiota config begin
void uc_static_active_time_init(unsigned char symbol_length);

wiota_cfg_t *uc_static_get_wiota_cfg(void);

wiota_sys_cfg_t *uc_static_get_wiota_sys_cfg(void);
void uc_static_set_wiota_sys_cfg(wiota_sys_cfg_t *sys_cfg);

wiota_act_cfg_t *uc_static_get_wiota_act_cfg(void);
void uc_static_set_wiota_act_cfg(wiota_act_cfg_t *act_cfg);

wiota_freq_cfg_t *uc_static_get_wiota_freq_cfg(void);
void uc_static_set_wiota_freq_cfg(wiota_freq_cfg_t *freq_cfg);

wiota_power_cfg_t *uc_static_get_wiota_power_cfg(void);
void uc_static_set_wiota_power_cfg(wiota_power_cfg_t *power_cfg);

wiota_rate_cfg_t *uc_static_get_wiota_rate_cfg(void);
void uc_static_set_wiota_rate_cfg(wiota_rate_cfg_t *rate_cfg);
unsigned char uc_static_get_max_mcs(unsigned char type);

wiota_paging_tx_cfg_t *uc_static_get_wiota_paging_tx_cfg(void);
void uc_static_set_wiota_paging_tx_cfg(wiota_paging_tx_cfg_t *paging_tx_cfg);

wiota_sync_paging_cfg_t *uc_static_get_wiota_sync_paging_cfg(void);
void uc_static_set_wiota_sync_paging_cfg(wiota_sync_paging_cfg_t *sync_paging_cfg);

wiota_ts_cfg_t *uc_static_get_wiota_ts_cfg(void);
void uc_static_set_wiota_ts_cfg(wiota_ts_cfg_t *ts_cfg);

wiota_subf_mode_cfg_t *uc_static_get_wiota_subf_mode_cfg(void);
void uc_static_set_wiota_subf_mode_cfg(wiota_subf_mode_cfg_t *subf_cfg);
//} wiota config end

//{ gateway config begin
gateway_cfg_t *uc_static_get_gateway_cfg(void);

gw_base_cfg_t *uc_static_get_gateway_base_cfg(void);
void uc_static_set_gateway_base_cfg(gw_base_cfg_t *base_cfg);

gw_id_manager_cfg_t *uc_static_get_gateway_id_manager_cfg(void);
void uc_static_set_gateway_id_manager_cfg(gw_id_manager_cfg_t *id_mng_cfg);

gw_auth_cfg_t *uc_static_get_gateway_auth_cfg(void);
void uc_static_set_gateway_auth_cfg(gw_auth_cfg_t *auth_cfg);

gw_net_policy_cfg_t *uc_static_get_gateway_net_policy_cfg(void);
void uc_static_set_gateway_net_policy_cfg(gw_net_policy_cfg_t *net_policy_cfg);

gw_net_if_cfg_t *uc_static_get_gateway_net_if_cfg(void);
void uc_static_set_gateway_net_if_cfg(gw_net_if_cfg_t *net_if_cfg);

gw_wifi_cfg_t *uc_static_get_gateway_wifi_cfg(void);
void uc_static_set_gateway_wifi_cfg(gw_wifi_cfg_t *net_wifi_cfg);

gw_cat1_cfg_t *uc_static_get_gateway_cat1_cfg(void);
void uc_static_set_gateway_cat1_cfg(gw_cat1_cfg_t *cat1_cfg);

gw_bt_cfg_t *uc_static_get_gateway_bt_cfg(void);
void uc_static_set_gateway_bt_cfg(gw_bt_cfg_t *bt_cfg);

gw_mqtt_server_cfg_t *uc_static_get_gateway_mqtt_cfg(void);
void uc_static_set_gateway_mqtt_cfg(gw_mqtt_server_cfg_t *mqtt_server_cfg);

gw_data_cfg_t *uc_static_get_gateway_data_cfg(void);
void uc_static_set_gateway_data_cfg(gw_data_cfg_t *data_cfg);

gw_wtd_cfg_t *uc_static_get_gateway_wtd_cfg(void);
void uc_static_set_gateway_wtd_cfg(gw_wtd_cfg_t *wtd_cfg);

gw_ftp_log_cfg_t *uc_static_get_gateway_log_cfg(void);
void uc_static_set_gateway_log_cfg(gw_ftp_log_cfg_t *log_cfg);

gw_log_switch_cfg_t *uc_static_get_gateway_log_switch_cfg(void);
void uc_static_set_gateway_log_switch_cfg(gw_log_switch_cfg_t *log_switch_cfg);

gw_uart_485_cfg_t *uc_static_get_gateway_uart_485_cfg(void);
void uc_static_set_gateway_uart_485_cfg(gw_uart_485_cfg_t *uart_485_cfg);

gw_timed_cfg_t *uc_static_get_gateway_timed_cfg(void);
void uc_static_set_gateway_timed_cfg(gw_timed_cfg_t *timed_cfg);
//} gateway config end

//{ sync assiatantconfig begin
sync_cfg_t *uc_static_get_sync_cfg(void);
void uc_static_set_sync_cfg(sync_cfg_t *sync_cfg);
//} sync assistant config end

//{ slot send config begin
slot_send_cfg_t *uc_static_get_slot_send_cfg(void);
void uc_static_set_slot_send_cfg(slot_send_cfg_t *slot_send_cfg);
//} slot send config end
#endif /* __CONFIG_API_H__ */
